﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using Utilities.QuickSql;
using MySql.Data;
namespace Deviseur_Cs2i_Car
{
    public partial class Accueil : Form
    {
        public Accueil()
        {
            try
            {
                XmlDocument document = new XmlDocument();
                document.Load("Database.xml");
                XmlNode node = document.DocumentElement;
                string Address = node.SelectNodes("Address").Item(0).InnerText.ToString();
                int Port = Convert.ToInt32(node.SelectNodes("Port").Item(0).InnerText.ToString());
                string Login = node.SelectNodes("Login").Item(0).InnerText.ToString();
                string Password = node.SelectNodes("Password").Item(0).InnerText.ToString();
                string Database = node.SelectNodes("Database").Item(0).InnerText.ToString();

                Program.Address = Address;
                Program.Port = Port;
                Program.Login = Login;
                Program.Password = Password;
                Program.Database = Database;

                Program.Db = new MySqlDatabase(Address, Port, Login, Password, Database);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }

            InitializeComponent();

            string NomEntreprise = Program.Db.QueryValue<string>("SELECT NomEntr FROM ENTR");
            this.NomEntreprise.Text = NomEntreprise;
            this.àProposDeToolStripMenuItem.Text = "À propos de " + NomEntreprise;

            DataTable DataTypeVoiture = new DataTable();

            DataTypeVoiture.Columns.Add("NumType");
            DataTypeVoiture.Columns.Add("LibelleType");
            DataTypeVoiture.Rows.Add("0", "- Choisir un type de voitur -");

            Table TypeVoiture = Program.Db.QueryTable("SELECT * FROM TYPE");
            foreach (Record r in TypeVoiture)
                DataTypeVoiture.Rows.Add(r.Values[0], r.Values[1]);

            this.comboTypeVoiture.DataSource = DataTypeVoiture;
            this.comboTypeVoiture.ValueMember = "NumType";
            this.comboTypeVoiture.DisplayMember = "LibelleType";

            this.comboTypeVoiture.SelectedIndex = 0;
        }

        private void quitterToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void àProposDeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Apropos FenApropos = new Apropos();
            FenApropos.ShowDialog();
        }

        private void comboTypeVoiture_SelectedIndexChanged(object sender, EventArgs e)
        {
            
            if (comboTypeVoiture.SelectedIndex != 0)
            {
                string DescrCategSQL = Program.Db.QueryValue<string>("SELECT DescriptionType FROM TYPE WHERE NumType = '" + comboTypeVoiture.SelectedValue.ToString() + "'");

                NomCategorie.Text = comboTypeVoiture.Text.ToString();
                DescrCategorie.Text = DescrCategSQL;
                button1.Visible = false;
                datavoiture.Visible = true;

                Table Voiture = Program.Db.QueryTable("SELECT NumVoi,NomVoi,PrixbaseVoi FROM VOITURE WHERE NumType = '" + comboTypeVoiture.SelectedValue.ToString() + "'");

                this.datavoiture.Rows.Clear();

                foreach (Record r in Voiture)
                    this.datavoiture.Rows.Add(r.Values[0], r.Values[1], r.Values[2]);
            }
            else
            {
                NomCategorie.Text = "";
                DescrCategorie.Text = "";
                button1.Visible = false;
                datavoiture.Visible = false;


                
            }
        }

        private void typeDeVoitureToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AdminType FenAdminType = new AdminType();
            FenAdminType.ShowDialog();
        }


        private void typeDeMoteurToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AdminHTDI FenAdminType = new AdminHTDI();
            FenAdminType.ShowDialog();
        }

        private void typeDuMoteurToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AdminTypeMoteur FenAdminTypeMoteur = new AdminTypeMoteur();
            FenAdminTypeMoteur.ShowDialog();
        }

        private void categorieDoptionToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AdminCategOption FenAdminCATEGOPTION = new AdminCategOption();
            FenAdminCATEGOPTION.ShowDialog();
        }

        private void contenanceDuMoteurToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AdminContenance FenAdminContenance = new AdminContenance();
            FenAdminContenance.ShowDialog();
        }

        private void motorisationMoteurToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AdminMotorisation FenAdminMotorisation = new AdminMotorisation();
            FenAdminMotorisation.ShowDialog();
        }

        private void couleurCarosserieToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AdminCouleurCaross FenAdminCouleurCaross = new AdminCouleurCaross();
            FenAdminCouleurCaross.ShowDialog();
        }

        private void voitureToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AdminVoiture FenAdminVoiture = new AdminVoiture();
            FenAdminVoiture.ShowDialog();
        }

        private void voitureToolStripMenuItem_Click_1(object sender, EventArgs e)
        {
            AdminVoiture FenAdminVoiture = new AdminVoiture();
            FenAdminVoiture.ShowDialog();
        }

        private void voitureMoteurToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AdminVoiMotor FenAdminVoitureMotor = new AdminVoiMotor();
            FenAdminVoitureMotor.ShowDialog();
        }

        private void optionsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AdminOption FenAdminOption = new AdminOption();
            FenAdminOption.ShowDialog();
        }

        private void sousOptionsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AdminSSOption FenAdminVoitureSSOption = new AdminSSOption();
            FenAdminVoitureSSOption.ShowDialog();
        }

        private void voitureOptionToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AdminVoiOption FenAdminVoiOption = new AdminVoiOption();
            FenAdminVoiOption.ShowDialog();
        }

        private void voitureCouleurCarrosserieToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AdminVoiCouleurCarross FenAdminVoiCouleurCarross = new AdminVoiCouleurCarross();
            FenAdminVoiCouleurCarross.ShowDialog();
        }

    }
}
